package com.ihelp.controller;

import com.ihelp.entities.CommonResult;
import com.ihelp.pojo.Area;
import com.ihelp.service.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LiuZiMing
 * @since 2023-06-01
 */
@RestController
@Slf4j
@RequestMapping("/area")
public class AreaController {

    @Autowired
    AreaService areaService;

    @GetMapping("/all")
    public CommonResult getAllArea(){
        List<Area> allArea = areaService.getAllArea();
        return new CommonResult<>(200,"获取所有地区成功",allArea);
    }

    @GetMapping("/id/{id}")
    public CommonResult getAreaById(@PathVariable Integer id){
        Area areaById = areaService.getAreaById(id);
        if (areaById!=null){
            return new CommonResult<>(200,"根据id:"+id+",获取地区成功",areaById);
        }else {
            return new CommonResult(204,"根据id:"+id+",未查询到地区");
        }
    }
}

